package servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSONObject;

import bean.AnimalBean;
import bean.UserBean;
import dao.AnimalDao;

/**
 * Servlet implementation class ListServlet
 */
@WebServlet("/list")
public class ListServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ListServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		
		String my = request.getParameter("user");
		
		// 需要救助的动物列表
		List<AnimalBean> animal_list = null;
		
		
		if (my==null) {
			animal_list = AnimalDao.query();
		}else {
			System.out.println(my);
			String user_phone = ((UserBean) request.getSession().getAttribute("now_user")).getUser_phone();
			animal_list = AnimalDao.query(user_phone);
			request.setAttribute("my", my);
		}
		
		
		request.setAttribute("animal_list", animal_list);
		
		request.getRequestDispatcher("/list.jsp").forward(request, response);
		
		
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
